<template>
  <div>
    <!-- 其他 -->
    <el-input
      v-model="dataForm.other"
      placeholder="请输入其他内容"
      class="w-full mt-1"
      type="textarea"
      :rows="20"
      maxlength="1000"
      show-word-limit
      @blur="handleBlur"
    />
  </div>
</template>

<script setup>
import { ref, onMounted, onBeforeUnmount } from "vue";
import { ElMessage, ElMessageBox } from "element-plus";
import { useUserStore } from "@/pinia";
import { watchStorage, setStorageWithEvent } from "@/utils/GlobalMonitoring.js";
import { handleApiResponse } from "@/utils/request.js";
import {
  QueryGlassesInfo,
  CreateGlassesInfo,
} from "../../../../../../../wailsjs/go/api/ReportApi";

onMounted(() => {});
const emit = defineEmits(["handleRefreshData"]);
const userStore = useUserStore();

const dataForm = ref({});

async function handleBlur() {
  handleApiResponse(() => CreateGlassesInfo(dataForm.value)).then((res) => {
    if (res.code == 0) {
      ElMessage.success("保存成功");
      userStore.updateOpticianEditStatus(1);
      emit("handleRefreshData");
    }
  });
}

// 接收数据
let cleanup2;
onMounted(() => {
  cleanup2 = watchStorage("scheme_data", (e) => {
    // console.log(e.data);
    dataForm.value = e.data || {};
  });
  return () => cleanup2();
});

onBeforeUnmount(() => {
  cleanup2();
});
</script>

<style scoped lang="scss">
</style>